<template>
  <div class="sent-command-list">
    <div class="sent-command-table-wrapper">
    <table class="sent-command-table">
      <thead>
        <tr>
          <th>指令名称</th>
          <th>指令内容</th>
          <th>发送时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="command in commands" :key="command.id">
          <td>{{ command.name }}</td>
          <td>{{ command.content }}
            <template v-if="command.parameter">
              <span class="parameter-value">(参数: {{ command.parameter }})</span>
            </template>
          </td>
          <td>{{ command.sentTime }}</td>
          <td>
            <button class="resend-btn" @click="onResendCommand(command)">恢复发送</button>
          </td>
        </tr>
      </tbody>
    </table>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue';

// 定义props
interface Command {
  id: number;
  name: string;
  content: string;
  parameter?: string;
  sentTime?: string;
}

defineProps<{
  commands: Command[];
}>();

// 定义emits
const emit = defineEmits<{
  (e: 'resend-command', command: Command): void;
}>();

// 方法：处理指令重发
const onResendCommand = (command: Command) => {
  emit('resend-command', command);
};
</script>

<style scoped>
.sent-command-list {
  overflow-y: auto;
  height: 100%;
  padding: 5px;
  box-sizing: border-box;
}

.sent-command-table-wrapper {
  overflow-x: auto;
}

.sent-command-table {
  width: 100%;
  min-width: 500px;
  border-collapse: collapse;
}

.sent-command-table th,
.sent-command-table td {
  padding: 10px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

.sent-command-table th {
  background-color: #f5f5f5;
  font-weight: bold;
  white-space: nowrap;
}

.parameter-value {
  margin-left: 10px;
  color: #666;
  font-style: italic;
  font-size: 14px;
}

.resend-btn {
  padding: 4px 10px;
  background-color: #4285f4;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .sent-command-table th,
  .sent-command-table td {
    padding: 8px;
  }

  .resend-btn {
    padding: 3px 8px;
    font-size: 12px;
  }
}
</style>